package com.itheima.listener;

import cn.hutool.crypto.SecureUtil;
import com.itheima.pojo.UserInfo;
import com.itheima.support.SysConsts;
import com.itheima.utils.RedisUtil;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

@Component
public class ServiceStartupListener implements BaseStartupListener {

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        //构建用户信息
        UserInfo zhangsan = new UserInfo();
        zhangsan.setUserId(1L);
        zhangsan.setUsername("zhangsan");
        zhangsan.setPassword(SecureUtil.md5("123"));
        zhangsan.setAuthority("add_checkitem,del_checkitem");

        //将数据放入到redis缓存中
        RedisUtil.set(SysConsts.USER_INFO_PREX_KEY + "zhangsan",zhangsan);

        UserInfo lisi = new UserInfo();
        lisi.setUserId(2L);
        lisi.setUsername("lisi");
        lisi.setPassword(SecureUtil.md5("456"));
        lisi.setAuthority("normal");
        RedisUtil.set(SysConsts.USER_INFO_PREX_KEY + "lisi",lisi);
    }

}
